//
//  CommunityDetailCell.m
//  cityStar
//
//  Created by joyban on 14-12-25.
//  Copyright (c) 2014年 tiny. All rights reserved.
//

#import "CommunityDetailCell.h"
#import "UIButton+WebCache.h"

@implementation CommunityDetailCell

+(CGFloat)heightOfTableCell
{
    return 82;
}

-(void)configWithMerchant:(MerchantDetail *)merchant
{
//    NSString *text = [NSString stringWithFormat:@"%@赞",merchant.parise];
//    self.goodLabel.text = text.length>0?text:@"0";
    if ([merchant.parise intValue]>0) {
        self.goodLabel.text = [NSString stringWithFormat:@"%i赞",[merchant.parise intValue]];
        [self.goodBtn setImage:[UIImage imageNamed:@"good_y"] forState:UIControlStateNormal];
    }else{
        self.goodLabel.text = @"0赞";
        [self.goodBtn setImage:[UIImage imageNamed:@"good_n"] forState:UIControlStateNormal];
    }
    self.NameLabel.text = [NSString stringWithFormat:@"%@",merchant.name];
    NSArray *refundArray = [[NSString stringWithFormat:@"%@",merchant.refund] componentsSeparatedByString:@","];
    [refundArray enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
        switch ([obj integerValue]) {
            case 1:
            {
                self.imageRefund.hidden = NO;
            }
                break;
            case 2:
            {
                self.imageRefund02.hidden = NO;
            }
                break;
            default:
                break;
        }
    }];
//    if (self.imageRefund.hidden == NO || self.imageRefund.hidden == NO) {
//        self.btntopLine.constant = 20;
//        self.LabelDown_line.constant = 23;
//    }else{
//        self.btntopLine.constant = 10;
//        self.LabelDown_line.constant = 13;
//    }

    NSArray *discountArray = [merchant.discount componentsSeparatedByString:@","];
    NSArray *buttonArray = [[NSArray alloc]initWithObjects:self.btn1,self.btn2,self.btn3,self.btn4,self.btn5,nil];
    NSLog(@"%@",discountArray);
    if(discountArray.count > 0)
    {
        [discountArray enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL *stop) {
            UIButton *senderbtn = buttonArray[idx];
            senderbtn.hidden = NO;
            switch ([obj integerValue]) {
                case 1:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"cheng"] forState:UIControlStateNormal];
                }
                    break;
                case 2:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"re"] forState:UIControlStateNormal];
                }
                    break;
                case 3:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"tuan"] forState:UIControlStateNormal];
                }
                    break;
                case 4:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"you"] forState:UIControlStateNormal];
                }
                    break;
                case 5:
                {
                    [senderbtn setBackgroundImage:[UIImage imageNamed:@"quan"] forState:UIControlStateNormal];
                }
                    break;
                default:
                    break;
            }
        }];
    }
}

- (void)awakeFromNib {
    self.btn1.layer.cornerRadius = 4;
    self.btn2.layer.cornerRadius = 4;
    self.btn3.layer.cornerRadius = 4;
    self.btn4.layer.cornerRadius = 4;
    self.btn5.layer.cornerRadius = 4;

    self.btn1.hidden = YES;
    self.btn2.hidden = YES;
    self.btn3.hidden = YES;
    self.btn4.hidden = YES;
    self.btn5.hidden = YES;

    self.imageRefund.hidden = YES;
    self.imageRefund02.hidden = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (IBAction)good_Action:(UIButton *)sender {
    [self.delegate sendergoodClick:sender];

}



@end
